﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
public partial class ttdoanhnghiep : System.Web.UI.Page
{

    
        
    protected void Page_Load(object sender, EventArgs e)
    {
       
        
        addCombobox.addcb(cbhuyen, "select * from tbl_huyen", "Huyen");
        addCombobox.addcb(cbkhucn, "select * from tbl_khucn", "KHUCN");
        addCombobox.addcb(cbnghanhcon, "select * from tbl_ncon where ma='01'", "ten");
       
        addCombobox.addcb(cbnhomnganh, "select * from tbl_nganh", "TenNganh");
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        if (!CheckValues.isExistIDDN(txtmasodn.Text))
        {
            Response.Write("<script language='JavaScript'> alert('Mã Số DN đã tồn tại. Vui lòng nhập Mã Số khác !!'); </script>");
            return;
        }
        else
        {
            DatabaseHandler db = new DatabaseHandler();
            db.connect();
            string sql = "insert into tbl_doanhnghiep values ('" + txtmasodn.Text
                                               + "','" + txtngphongvan.Text + "','" + txtngayphongvan.Text + "','" + txttendn.Text + "','" + txttenta.Text + "','"
                                               + txttenvt.Text + "','" + cbnhomnganh.Text + "','" + cbnghanhcon.Text + "','" +
                                               cbloaidn.Text + "','" + cbkhucn.Text + "','" + cbhuyen.Text + "','"
                                               + txtdiachi.Text + "','" + txtdt.Text + "','" + txtfax.Text + "','" + txtwebsite.Text + "','" + txtemail.Text + "')";

            db.ThemDuLieu(sql);
            Variables.IDDN = txtmasodn.Text;

            db.insertIDDN(Variables.IDDN, "tbl_o");
            db.insertIDDN(Variables.IDDN, "tbl_h");
            db.insertIDDN(Variables.IDDN, "tbl_t");
            db.insertIDDN(Variables.IDDN, "tbl_m");
            db.insertIDDN(Variables.IDDN, "tbl_f");
            db.insertIDDN(Variables.IDDN, "tbl_k");
            db.close();
            lbShow.Text = "Lưu thông tin doanh nghiệp thành công!";
            if (Variables.roleFlag)
            {
                btn_NhapChiSo.Enabled = true;
            }
        }
    }


    protected void btn_NhapChiSo_Click(object sender, EventArgs e)
    {
        Response.Redirect("GiatriOrganization.aspx");
    }
    protected void cbnhomnganh_SelectedIndexChanged(object sender, EventArgs e)
    {
        addCombobox.addcb(cbnhomnganh, "select * from tbl_nganh", "TenNganh");
        cbnghanhcon.Items.Clear();
        string chose = "";
        chose = cbnhomnganh.SelectedItem.ToString();
        addCombobox.addcb(cbnghanhcon, "select * from tbl_ncon where NHOMNGANH='"+ chose +"'", "ten");
        cbnhomnganh.Items.Clear();
        addCombobox.addcb(cbnhomnganh, "select * from tbl_nganh", "TenNganh");
        cbnhomnganh.Text = chose;

    }
   
    
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");
    }

    protected void LinkButton16_Click1(object sender, EventArgs e)
    {
        Response.Redirect("Nhap_TTDoanhNghiep.aspx");
    }
    protected void LinkButton17_Click1(object sender, EventArgs e)
    {
        Response.Redirect("HienThi_TTDoanhNghiep.aspx");
    }
    protected void LinkButton24_Click1(object sender, EventArgs e)
    {
        Response.Redirect("Xuatdulieu.aspx");
    }
}